<?php

namespace app\man\controller;

use think\Controller;
use think\Db;
use think\Paginator;
use think\Cache;
use think\Request;
class Arrive extends Common
{
	public function dlist(){
		 
		$domains = Db::name("arrive")->paginate();

		$this->assign('list',$domains);

		return $this->fetch('list');
	}

	public function add(){

		return $this->fetch('add');
	}
	public function doadd()
	{

		$domains = input('domains');
		$lists = explode("\n",$domains);
		foreach($lists as $k=>$val){
			$data[$k]['domain']=trim($val);
			$data[$k]['status']=1;
		}
		$result = Db::name("arrive")->insertAll($data);
		if($result){
			$this->success('添加成功', url('man/arrive/add'), 3);
		}else{
			$this->success('添加失败');
		}

	}

	public function change(){
		$aid=input('aid');
		$status=input('status');

		if($status==2){
			$res = Db::name("arrive")->where('id',$aid)->update(['status'=>$status,'start_time'=>date("Y-m-d H:i:s")]);
		}else{
			$res = Db::name("arrive")->where('id',$aid)->update(['status'=>$status]);
		}

		if($status==3){
			$res = Db::name("arrive")->where('id',$aid)->update(['status'=>$status,'end_time'=>date("Y-m-d H:i:s")]);
		}else{
			$res = Db::name("arrive")->where('id',$aid)->update(['status'=>$status]);
		}
		if($status ==1){
			$res = Db::name("arrive")->where('id',$aid)->update(['status'=>$status]);
		}
		Cache::store('redis')->set('arrive',NULL,1);
		if($res===false){
			return false;
		}else{
		return true;
		}

	}

	public function delete(){
		$id = input('id');

		$res = Db::name('arrive')->where('id',$id)->delete();

		if($res){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}
}
